package exception_handling;

import static java.lang.System.out;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class SimpleStatement {
	// JDBC driver name and database URL
	static final String JDBC_DRIVER = "org.sqlite.JDBC";
	static final String DB_URL = "jdbc:sqlite:d:/sqlite/test.db";

	public static void main(String[] args) {

		try {
			Class.forName(JDBC_DRIVER);
			
			String sql = "SELECT id, first, last, age FROM emp";
			
			try (Connection con = DriverManager.getConnection(DB_URL);
					Statement stm = con.createStatement();
					ResultSet rs = stm.executeQuery(sql);) {

					while (rs.next()) {

						// Display values
						out.print("ID: " + rs.getInt("id"));
						out.print(", Age: " + rs.getInt("age"));
						out.print(", First: " + rs.getString("first"));
						out.println(", Last: " + rs.getString("last"));
					}
			}catch (SQLException ex) {
				ex.printStackTrace();
			}
			
		} catch (ClassNotFoundException ex) {
			ex.printStackTrace();
		} 
	}
}
